﻿using System;
using System.Collections.Generic;

namespace NDK.LocalUtils
{
    class XWDMesUpload:Upload
    {
        private static log4net.ILog m_Logger = log4net.LogManager.GetLogger("XWDMesUpload");

        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> login(string url, string username, string password, string siteId, string operation, string resource)
        {
            try
            {
                string loginurl = url + "swd/http/pack/equipmentIntegratedAction!logIn.action?";
                Dictionary<string, string> parameters = new Dictionary<string, string>();
                parameters.Add("username", username);
                parameters.Add("password", password);
                parameters.Add("siteId", siteId);
                parameters.Add("OPERATION", operation);
                parameters.Add("RESOURCE", resource);
                Dictionary<string, string> loginResult = PostAndGet(loginurl, parameters);
                return loginResult;
            }
            catch (Exception ex)
            {
                m_Logger.Error("登录错误：" + ex.StackTrace);
                return null;
            }
        }
        /// <summary>
        /// 检查过站信息
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> checkStation(string url, string jession, string packBarcode)
        {
            try
            {
                string checkurl = url + "swd/http/pack/equipmentIntegratedAction!doCheckOperation.action?dataJson={"+'"'+"JSESSION"+'"'+":"
                    +'"'+jession+'"'+","+'"'+"PACK_BARCODE"+'"'+":"+'"'+packBarcode+'"'+"}";
                Dictionary<string, string> checkResult = PostAndGet(checkurl);
                return checkResult;
            }
            catch (Exception ex)
            {
                m_Logger.Error("检查过站信息错误：" + ex.StackTrace);
                return null;
            }
        }
        /// <summary>
        /// 获取数据收集编号
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> getTestId(string url, string jession)
        {
            try
            {
                string getTestidUrl = url + "swd/http/pack/equipmentIntegratedAction!dotestid.action?";
                Dictionary<string, string> parameters = new Dictionary<string, string>();
                parameters.Add("JSESSION", jession);
                Dictionary<string, string> testIdResult = PostAndGet(getTestidUrl, parameters);
                return testIdResult;
            }
            catch (Exception ex)
            {
                m_Logger.Error("获取数据收集编号错误：" + ex.StackTrace);
                return null;
            }
        }

            /// <summary>
        /// 上传
        /// </summary>
        /// <param name="url"></param>
        /// <param name="jession"></param>
        /// <param name="testId"></param>
        /// <param name="batBarcode"></param>
        /// <param name="packBarcode"></param>
        /// <param name="errorCode"></param>
        /// <param name="result"></param>
        /// <param name="dcGroup"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public Dictionary<string, string> upload(string url, string jession, string testId, string packBarcode, string errorCode, string result, string dcGroup, string data)
        {
            try
            {
                string uploadUrl = url + "swd/http/pack/equipmentIntegratedAction!doRecordData.action?dataJson={"
                    + '"' + "JSESSION" + '"' + ":" + '"' + jession + '"' + ","
                    + '"' + "TESTID" + '"' + ":" + '"' + testId + '"' + ","
                    + '"' + "PACK_BARCODE" + '"' + ":" + '"' + packBarcode + '"' + ","
                    + '"' + "ERROR_CODE" + '"' + ":" + '"' + errorCode + '"' + ","
                    + '"' + "RESULT" + '"' + ":" + '"' + result + '"' + ","
                    + '"' + "DC_GROUP" + '"' + ":" + '"' + dcGroup + '"' + ","
                    + '"' + "DATA" + '"' + ":" + data + "}";
                  Dictionary<string,string> testIdResult=PostAndGet(uploadUrl);
                return testIdResult;
            }
            catch (Exception ex)
            {
                m_Logger.Error("上传错误：" + ex.StackTrace);
                return null;
            }
        }


    }
}
